package fr.cnam.ratpProject.client.activities.lineMap;

import com.google.gwt.geolocation.client.Position;
import com.google.gwt.maps.client.MapType;
import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.control.LargeMapControl;
import com.google.gwt.maps.client.control.MenuMapTypeControl;
import com.google.gwt.maps.client.geom.LatLng;
import com.google.gwt.maps.client.overlay.Layer;
import com.google.gwt.maps.client.overlay.Marker;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;

import fr.cnam.ratpProject.client.activities.lineMap.LineMap.LineMapView;

public class LineMapViewImpl extends Composite implements LineMapView {

	private VerticalPanel mainContent = new VerticalPanel();
	
	public LineMapViewImpl(){
		initWidget(mainContent);
	}

	@Override
	public void buildUi() {
		LatLng position = LatLng.newInstance(48.857233, 2.352276);
		createMap(position);
	}

	private void createMap(LatLng position) {
		MapWidget map = new MapWidget(position, 12);
		map.setContinuousZoom(true);
		map.setDraggable(true);
		map.setSize("100%", "100%");
	    map.addMapType(MapType.getAerialHybridMap());
	    map.addOverlay(new Marker(position));
		map.addControl(new LargeMapControl());
		map.addControl(new MenuMapTypeControl());
		map.addOverlay(Layer.newInstance(""));
		mainContent.add(map);
		mainContent.setSize("100%", "100%");
	}

	@Override
	public void buildUi(Position pos) {
		LatLng position = LatLng.newInstance(pos.getCoordinates().getLatitude(), pos.getCoordinates().getLongitude());
		createMap(position);
	}

}
